<?php
	include 'constants.php';
	
	$con = get_connection();
	$name = $_POST["title"];
	$start_time = $_POST["when_dateIntlDisplay"];
	$ticket_amount = $_POST['ticket_amount'];
	$description = $_POST["details"];
	$new_event = array('name' => $name, 'start_time' => $start_time, 'description' => $description);
	$result = $fb->api('/'.$user.'/events', 'POST', $new_event);
	$event_id = $result['id'];
	
	echo $event_id;
	$xmlfile='seatchart.xml';
	create_new_xml_event_table(strval($event_id), $xmlfile, $con);
	
	close_connection($con);
	
	$feed_dir = '/'.$user.'/feed/';  //to the UID you want to send to
	$message_str =  'I have created an event called '.$name.'!';
	$msg_body = array('access_token' => $access_token,
			'name' => $name,
			'message' => $message_str,
			'description' => $description,
			'caption' => $name,
			'link' => 'http://localhost/hophacks/event_page.php?event_id='.$event_id,
			'actions' => array(array('name' => 'Grab a seat!',
					'link' => 'http://localhost/hophacks/event_page.php?event_id='.$event_id))
	);
	try {
		//this is the API call that does it all
		$result = $fb->api($feed_dir, 'post', $msg_body);
	}
	catch (Exception $e) {
		$err_str = $e->getMessage();
	}
		
	header('Location:event_page.php?event_id='.$event_id);	
?>